import org.junit.Assert.*
import org.junit.Ignore
import org.junit.Test
import java.io.File
import java.io.IOException
import java.nio.file.Files
import java.util.stream.Collectors

class TrickyKotlin7Test {
    @Test @Ignore
    fun cannotUseIllegalThings() = try {
        val lines = Files.lines(File("src/main/kotlin/Test.kt").toPath())
                .filter(String::isNotBlank)
                .collect(Collectors.toList())
        assertEquals("Should be only one line!", 1, lines.size)
        val line = lines.first()
        assertFalse("Cannot use split!", "split" in line)
        assertTrue("Cannot be more than 95 characters!", line.length <= 95)
        println(line.length)
    } catch (e: IOException) {
        fail("Failed to read the source file.")
    }

    @Test
    fun exampleTests() {
        assertEquals("You {{need}} <extra> time ( or money )", f("You }}need{{ >extra< time ) or money ("))
        assertEquals("<br/>", f(">br/<"))
    }

    fun String.convertStr() = replace(Regex("[1-6]")) { "${")(}{><"["123456".indexOf(it.value[0])]}" }

    @Test
    fun finalTests() {
        repeat(100) {
            val s = "${Math.random()}${Math.random()}${Math.random()}${Math.random()}${Math.random()}${Math.random()}".convertStr()
            assertEquals(trueSolution(s), f(s))
        }
    }

    fun trueSolution(s: String) = s.replace(Regex("[(){}<>]")) { "${")(}{><"["(){}<>".indexOf(it.value[0])]}" }
//    fun f(s:String)="({<>})".run{s.map{plus(it)[5-indexOf(it)]}.joinToString("")}
//    fun f(s:String)=s.map{"$it)(><}{"["()<>{}".indexOf(it)+1]}.joinToString("")
//    fun f(s:String)=s.replace(Regex("[()><{}]")){")(<>}{"["()><{}".indexOf(it.value)]+""}
//    fun f(s:String)=s.replace(Regex(b)){b[7-b.indexOf(it.value)]+""}val b ="[){><}(]"
    fun f(a:String)=a.fold(""){s,c->s+"{)<>(}$c"[5-"{)<>(}".indexOf(c)]}
//    fun f(s:String)=s.fold(""){s,c->"{)<>(}".let{s+(c+it)[6-it.indexOf(c)]}}
}